home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-07 | 5.6 KB | 154 lines | [TEXT/MPS ] |
- ; file SafeStart.a
- ;
- ;
- ;
- ; This little piece of 68000 code is an header for Macintosh applications compiled under MPW,
- ; that does a clean job of warning the user when running on a 64K ROM machine.
- ;
- ; This is usefull because, under MPW 3.2 QR2, the default MPW initialisation code calls
- ; Get1NamedResource blindly, without checking that the machine has at least 128K ROMs.
- ; If running on a Macintosh XL, Macintosh 512, or Macintosh 128, Get1NamedResource does not
- ; exist and SetPtrSize gets called instead. This does not always cause a bomb, but it's
- ; unadvisable anyway.
- ;
- ; Another reason to use this piece of code to perform the ROM version check is that many things
- ; like MaxApplZone don't work any longer under MPW 3.2 QR2; this is why Sample.c and Sample.p
- ; as well as MacApp sample applications bomb when compiled with MPW 3.2 QR2 and run on a
- ; 64K ROM machine (usually with ID=02)
- ;
- ; SafeStart's strategy is to define an alternate entry point, which overides the default one;
- ; the code does the necessary check, then jumps into the default entry point for C applications.
- ; (it's name %__MAIN seems hard-coded in the MPW linker)
- ;
- ; Instruction for use :
-
- ; - for application's whose entry point is in Pascal, a little work is needed to convert to
- ; the native C entry point :
- ; - at the beginning of the main program file change
- ; PROGRAM Whatever;
- ; to
- ; UNIT Whatever;
- ; INTERFACE
- ; PROCEDURE MAIN; {the entry point}
- ; IMPLEMENTATION
- ; - before the mains program's ‘BEGIN’, add :
- ; PROCEDURE MAIN;
- ; - at the end of the main program, before the final ‘END.’ insert
- ; END; {end of MAIN}
- ; - add the option ‘-ma main=MAIN’ to the Link command line
- ;
- ; - assemble this file SafeStart.a into SafeStart.a.o , and Link with it
- ; (although not currently required, it is advisable that it be the first link file)
- ;
- ; - preferably, add an ALRT ressource (ID=13579) and associated DITL, to be displayed when
- ; running on old machines (if it's missing, the application will just return to Finder);
- ; since the Alert is a StopAlert, leave room on the top left for the stop icon;
- ; an example alert, in Rez format, is included at the end of this file.
- ;
- ; - optionaly, remove checks for 128K ROMs (search ROM85, 28E, machineType, etc…)
- ; from the source code, probably saving more code than SafeStart adds.
- ;
- ;
- ; This is brought to you by François Grieu - RMT & Hello Informatique, France (hence the typos)
- ; APPLELINK : FRA0003
- ;
- ; Although this has been carefully tested (under MPW 3.2 QR2, with at least Sample.c, Sample.p,
- ; CPlusTESample, and MacApp 2.0.1 Calc), the author assume no reponsability for possible errors.
- ;
- ; Feel free to use, redistribute and alter in any way.
- ;
- ;
- ; revision history
- ;
- ; 1.01 910217 FRG added explanations on how to use if the application is in Pascal;
- ; smoothed comments; code unchanged.
- ;
- ; 1.00 910211 FRG first release version, for MPW 3.2 QR2
- ;
- ;————————————————————————————————————————————————————————————————————————————————————————————————
- ;
- ; assembly options
- ;
- kALRTidOld EQU 13579 ; id of the ALRT displayed on old machines; change as needed
- ;————————————————————————————————————————————————————————————————————————————————————————————————
- INCLUDE 'SysEqu.a'
- INCLUDE 'Traps.a'
- ;————————————————————————————————————————————————————————————————————————————————————————————————
- ; this is the entry point; to avoid using too much CODE0001 space, most of the code is placed
- ; in the initialisation segment %A5Init, and will get unloaded with _DATAINIT (hopefully)
- SEG 'Main'
- %_SafeEntry MAIN EXPORT
- IMPORT (%_SafeCheck,%__MAIN):CODE
- JSR %_SafeCheck ; check for 64K ROMs machine
- JMP %__MAIN ; do whatever MPW wants
- ENDMAIN ; end of main procedure %_SafeEntry
- ;————————————————————————————————————————————————————————————————————————————————————————————————
- ; this is the ‘bulk’ of the code
- SEG '%A5Init'
- %_SafeCheck PROC EXPORT
-
- TST.W ROM85 ; check the kind of machine
- BMI.S OldROMs ; -> it's a 64K ROMs machine
- RTS ; we are safe
- ; an old machine; first of all we must initialize the managers
- OldROMs PEA -4(A5) ; the usual and safe place for QD globals
- _InitGraf ; don't flush events (_StopAlert will do)
- _InitFonts
- _InitWindows
- _InitMenus
- _TEInit
- CLR.L -(A7)
- _InitDialogs
- _InitCursor ; make cursor an arrow
- ; display the alert
- ; NB1: we don't care for the stack since we won't return; this saves 2 instructions
- ; NB2: the system is smart enough to just go on if the ALRT is not available
- ; NB3: since MultiFinder can't be running the default button will be outlined correctly
- MOVE.W #kALRTidOld,-(A7)
- CLR.L -(A7)
- _StopAlert ; StopAlert(kALRTidOld,nil)
- ; exit to Finder
- _ExitToShell
-
- ENDPROC ; end of procedure %_SafeCheck
- ;————————————————————————————————————————————————————————————————————————————————————————————————
- END ; end of file SafeStart.a
-
-
- ; asm "{active}" # use SafeStart.a.o as the first link file
-
- ; you can paste the following into your .r file to get an appropriate ALRT and DITL
-
- resource 'ALRT' (13579, purgeable) {
- {40, 36, 120, 332},
- 13579,
- { /* array: 4 elements */
- /* [1] */
- OK, visible, sound3,
- /* [2] */
- OK, visible, sound3,
- /* [3] */
- OK, visible, sound3,
- /* [4] */
- OK, visible, sound3
- }
- };
-
- resource 'DITL' (13579, purgeable) {
- { /* array DITLarray: 2 elements */
- /* [1] */
- {50, 170, 70, 249},
- Button {
- enabled,
- "Cancel"
- },
- /* [2] */
- {10, 70, 44, 289},
- StaticText {
- disabled,
- "Sorry, but this application needs\n"
- "newer ROMs to run safely."
- }
- }
- };
-